package cn.keniykey.mc.landterritory.database;

import java.sql.SQLException;
import java.sql.Statement;

import cn.keniykey.mc.landterritory.toolkit.DebugUtil;

public final class DataBaseCoreSqlite extends AbDataBaseCore{
	private AbDataBase database;
	
	DataBaseCoreSqlite(AbDataBase database) {
		this.database = database;
	}
	
	@Override
	public AbDataBase getDataBase() {
		return this.database;
	}
	@Override
	protected void initDataBase() throws SQLException {
		final String land_data = "create table if not exists land_data (id integer primary key autoincrement not null unique," +
				"owner varchar(40) not null, name nvarchar(32) not null unique, type int default 0, range text not null, pos text not null, flags text, parameter text, "
				+ "level int default 1, price int default -1, overlap boolean default 0,system boolean default 0);";
		final String land_message = "create table if not exists land_message (id integer primary key not null unique, entertip nvarchar(200), leavetip nvarchar(200));";
		final String land_amount = "create table if not exists land_amount (player varchar(40) not null unique, amount int default 0);";
		DebugUtil.info("数据库指令[initDataBase][Sqlite]：准备数据库中");
		try(final Statement sm = this.database.getConnection().createStatement()) {
			sm.execute(land_data);
			DebugUtil.info("数据库指令[initDataBase][Sqlite]：准备数据库中1/3");
			sm.execute(land_message);
			DebugUtil.info("数据库指令[initDataBase][Sqlite]：准备数据库中2/3");
			sm.execute(land_amount);
		}catch(SQLException ex) {
			DebugUtil.info("数据库指令[initDataBase][Sqlite]：准备数据库过程中出现错误");
			DebugUtil.info(ex);
		}
		DebugUtil.info("数据库指令[initDataBase][Sqlite]：数据库准备完毕");
	}
}